package com.elitel.common.businessJdbc.mongodb;

import java.util.Map;

import com.elitel.common.businessJdbc.BusinessSelectPreparedStatement;

public class MongoSelectStatement extends BusinessSelectPreparedStatement{

    // here return entire select statement without placeHolder
    // will convert sql into mongodb query syntax in mongodb handler
    @Override
    public String getPrecompileSql() {
        return isPageable() ? sqlTemplate() + containPageableSqlSection() : sqlTemplate();
    }

    // here is override containPlaceHolderCondition , replace place holder by using real value
    @Override
    protected String containPlaceHolderCondition(){
        if(conditionSection.isEmpty())
            return "";

        StringBuilder sb = new StringBuilder();
        for(Map.Entry<String, Object> conditionItem : conditionSection.entrySet()){
            sb.append(" AND ")
                .append(conditionItem.getKey())
                .append(fieldConditionSymbol.get(conditionItem.getKey()))
                // here is using 'content' i thinking is ok Test
                .append(" '").append(passCondition.get(conditionItem.getKey())).append("' ");
        }

        return sb.toString();

    }

    public String containPageableSqlSection(){
        StringBuilder sb = new StringBuilder();
        sb.append(" LIMIT ")
            .append(getPageNumber() - 1)
            .append(",")
            .append(getPageSize());
        return sb.toString();
    }

}
